package com.heking.security.sensitive;

import android.view.View;

/**
 * 敏感数据绑定工具
 * @Author 35574
 * @Date 2021/11/16
 * @Description
 */
public class SensitiveBinder  {
    /**
     * 绑定脱敏状态切换事件
     * @param eventView 绑定点击事件的View,单击切换脱敏状态
     * @param listener 脱敏状态改变监听器
     */
    public static void bindData(View eventView, OnSensitiveChangeListener listener) {
        if (eventView != null) {
            eventView.setTag(true);//默认脱敏
            if (listener != null) {
                listener.onChange(true);
            }
            eventView.setClickable(true);
            eventView.setOnClickListener(v -> {
                Object tag = eventView.getTag();
                if (tag instanceof Boolean) {
                    boolean isHide = (boolean) tag;
                    if (isHide) {
                        eventView.setTag(false);
                        if (listener != null) {
                            listener.onChange(false);
                        }
                    } else {
                        eventView.setTag(true);
                        if (listener != null) {
                            listener.onChange(true);
                        }
                    }
                }
            });
        }

    }
}
